package com.service.impl;

import com.dao.OrderProductDao;
import com.dao.ProductDao;
import com.dao.impl.OrderProductDaoImpl;
import com.dao.impl.ProductDaoImpl;
import com.pojo.OrderProduct;
import com.service.OrderProductService;

import java.util.List;

public class OrderProductServiceImpl implements OrderProductService {

    private OrderProductDao dao = new OrderProductDaoImpl();

    @Override
    public List<OrderProduct> rank() {
        List<OrderProduct> list = dao.rank();
        ProductDao productDao = new ProductDaoImpl();
        for (OrderProduct orderProduct : list) {
            orderProduct.setProduct(productDao.findByID(orderProduct.getProductId()));
        }
        return list;
    }

    @Override
    public int addOPD(OrderProduct orderProduct) {
        return dao.addOPD(orderProduct);
    }

    @Override
    public List<OrderProduct> findByOrderID(String orderID) {
        return dao.selectByOrderID(orderID);
    }
}
